package nix.servlet;

import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import java.net.URLEncoder;
import java.util.Arrays;

public class TestUrlEncoding {

	/**
	 * Url编码、解码
	 * 
	 * @param args
	 * @throws Exception
	 */
	public static void main(String[] args) throws Exception {

		String name = "张三";
		byte[] bs = name.getBytes();
		System.out.println(Arrays.toString(bs));
		// [-27, -68, -96, -28, -72, -119]
		// +256，转为16进制，加%
		// [%E5, %BC, %A0, %E4, %B8, %89]
		String nameEncode = URLEncoder.encode(name, "utf-8");
		System.out.println(nameEncode);
		// %E5%BC%A0%E4%B8%89
		String nameDecode = URLDecoder.decode(nameEncode, "utf-8");
		System.out.println(nameDecode);
	}

}
